<?php
class PartnerListWidget extends CWidget
{
    public $page_size = 10;

    public function run()
    {
        $this->page_size = intval($this->page_size);
        
        $criteria = new CDbCriteria();
        $criteria->with = array(
            'localePartner' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('t.status',Partner::STATUS_ACTIVE);
        $criteria->order = 't.create_time DESC, t.id DESC';
        $countPartner = Partner::model()->count($criteria);
        $paging = new CPagination($countPartner);
        $paging->pageSize = $this->page_size;
        $paging->applyLimit($criteria);
        
        $models = Partner::model()->findAll($criteria);
        $this->render('partner-list',array('models'=>$models,'paging'=>$paging));
    }
}
